<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui">
<h:body>

	<ui:composition template="/template/template.xhtml">

		<ui:define name="content">
			<h:form id="teacherForm">

				<p:panel header="Điều Kiện Tìm Kiếm" columns="1" cellpadding="0"
					style="width:100%">
					<h:panelGrid header="Tìm Kiếm Khoa" columns="3" cellpadding="1"
						style="width:40%">
						<h:outputLabel value="Khoa (*)" for="depId" />
						<p:selectOneMenu style="width:300px"
							value="#{mbTeacher.filter.depId}" required="true" id="depId">
							<f:selectItem itemLabel="Chọn ..." itemValue="" />
							<f:selectItems value="#{mbTeacher.depMap}" />
						</p:selectOneMenu>
						<p:commandButton value="Tìm Kiếm"
							actionListener="#{mbTeacher.search}"
							update=":teacherForm:teacherTablePanel"></p:commandButton>

					</h:panelGrid>
				</p:panel>
				<p:panel id="teacherTablePanel" style="width:100%">
					<p:dataTable id="teacherTable" var="item" paginator="true" rows="5"
						paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink}
											{PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
						value="#{mbTeacher.list}" rowKey="#{item.id}"
						selection="#{mbTeacher.selected}" selectionMode="single">

						<p:ajax event="rowSelect" listener="#{mbTeacher.onRowSelect}"
							update=":teacherForm:commandPanel">
						</p:ajax>

						<p:column>
							<f:facet name="header">
								<h:outputText value="Mã Khoa" />
							</f:facet>
							<h:outputText value="#{item.depId}" />
						</p:column>

						<p:column>
							<f:facet name="header">
								<h:outputText value="Mã CN" />
							</f:facet>
							<h:outputText value="#{item.majorId}" />
						</p:column>

						<p:column>
							<f:facet name="header">
								<h:outputText value="Mã GV" />
							</f:facet>
							<h:outputText value="#{item.teacherId}" />
						</p:column>
						<p:column>
							<f:facet name="header">
								<h:outputText value="Tên GV" />
							</f:facet>
							<h:outputText value="#{item.name}" />
						</p:column>

						<p:column>
							<f:facet name="header">
								<h:outputText value="Ngày Sinh" />
							</f:facet>
							<h:outputText value="#{item.birhday}" pattern="dd/MM/yyyy" />
						</p:column>

						<p:column>
							<f:facet name="header">
								<h:outputText value="Nơi Sinh" />
							</f:facet>
							<h:outputText value="#{item.birthPlace}" />
						</p:column>

						<p:column>
							<f:facet name="header">
								<h:outputText value="Địa Chỉ" />
							</f:facet>
							<h:outputText value="#{item.address}" />
						</p:column>

						<p:column>
							<f:facet name="header">
								<h:outputText value="Email" />
							</f:facet>
							<h:outputText value="#{item.email}" />
						</p:column>

						<p:column>
							<f:facet name="header">
								<h:outputText value="Học Hàm" />
							</f:facet>
							<h:outputText value="#{item.academicTitle}" />
						</p:column>

						<p:column>
							<f:facet name="header">
								<h:outputText value="Học Vị" />
							</f:facet>
							<h:outputText value="#{item.degree}" />
						</p:column>

						<p:column>
							<f:facet name="header">
								<h:outputText value="Cấp GV" />
							</f:facet>
							<h:outputText value="#{item.teacherType}" />
						</p:column>

						<p:column>
							<f:facet name="header">
								<h:outputText value="Ngày Hợp Đồng" />
							</f:facet>
							<h:outputText value="#{item.contractDate}" />
						</p:column>
						
						<p:column>
							<f:facet name="header">
								<h:outputText value="Loại Hợp Đồng" />
							</f:facet>
							<h:outputText value="#{item.contractType}" />
						</p:column>

						<p:column>
							<f:facet name="header">
								<h:outputText value="Hệ Số Lương" />
							</f:facet>
							<h:outputText value="#{item.salaryFactor}" />
						</p:column>

						<p:column>
							<f:facet name="header">
								<h:outputText value="Hệ Số TG" />
							</f:facet>
							<h:outputText value="#{item.teachingFactor}" />
						</p:column>

						<p:column>
							<f:facet name="header">
								<h:outputText value="Chủ Nhiệm Lớp" />
							</f:facet>
							<h:outputText value="#{item.clazzId}" />
						</p:column>

					</p:dataTable>
					<h:panelGrid id="commandPanel" columns="3">
						<p:commandButton id="addItem" value="Thêm" update=":editItemDlg"
							disabled="#{mbTeacher.filter.depId == null}"
							action="#{mbTeacher.prepareAdd}"
							oncomplete="editItemDlgWidget.show()"></p:commandButton>
						<p:commandButton id="editItem" value="Sửa"
							action="#{mbTeacher.prepareEdit}" update=":editItemDlg"
							disabled="#{mbTeacher.editMode == false}"
							oncomplete="editItemDlgWidget.show()"></p:commandButton>
						<p:commandButton id="deleteItem" value="Xóa"
							onclick="confirmation.show()"
							disabled="#{mbTeacher.editMode == false}">
						</p:commandButton>
					</h:panelGrid>

				</p:panel>
				<p:confirmDialog id="confirmDialog" message="Bạn Có Chắc Muốn Xóa?"
					width="250" header="Xác nhận xóa" severity="alert"
					widgetVar="confirmation">

					<p:commandButton id="confirm" value="Đồng Ý"
						update="teacherTable,commandPanel"
						oncomplete="confirmation.hide()"
						actionListener="#{mbTeacher.doDelete}" />
					<p:commandButton id="decline" value="Không Đồng Ý"
						onclick="confirmation.hide()" type="button" />

				</p:confirmDialog>
			</h:form>

			<script type="text/javascript">
				function handleTeacherRequest(xhr, status, args) {
					if (args.validationFailed) {
						jQuery('#editItemDlgWidget').effect("shake", {
							times : 3
						}, 100);
					} else {
						editItemDlgWidget.hide();
					}
				}
			</script>


			<p:growl id="growl" showDetail="true" sticky="true" />
			<p:dialog id="editItemDlg"
				header="#{mbTeacher.editMode == true ? 'Sửa Thông Tin Giảng Viên' : 'Thêm Giảng Viên Mới'}"
				minWidth="500" widgetVar="editItemDlgWidget" resizable="false">
				<p:ajax event="close" update=":teacherForm:teacherTablePanel"
					listener="#{mbTeacher.handleClose}" />
				<h:form id="editForm">
					<p:messages id="messages" showDetail="true" autoUpdate="true"
						showSummary="false" />
					<h:panelGrid columns="2" style="margin-bottom:10px">
						<h:outputLabel for="depId" value="Mã Khoa(*) " />
						<p:inputText id="depId" value="#{mbTeacher.item.depId}"
							required="true" label="Mã Khoa" size="50" disabled="true" />

						<h:outputLabel for="teacherId" value="Mã Giảng Viên(*) " />
						<p:inputText id="teacherId" value="#{mbTeacher.item.teacherId}"
							required="true" label="Mã Giảng Viên" size="50" disabled="true" />

						<h:outputLabel for="major" value="Chuyên Ngành " />
						<p:selectOneMenu style="width:350px"
							value="#{mbTeacher.item.majorId}" required="false" id="major">
							<f:selectItem itemLabel="Chọn..." itemValue="" />
							<f:selectItems value="#{mbTeacher.majorMap}" />
						</p:selectOneMenu>

						<h:outputLabel for="teacherName" value="Tên Giảng Viên(*) " />
						<p:inputText id="teacherName" value="#{mbTeacher.item.name}"
							required="true" label="Tên Giảng Viên" size="50" />

						<h:outputText for="birthDate" value="Ngày Sinh "></h:outputText>
						<p:calendar id="birthDate" label="Ngày Sinh"
							value="#{mbTeacher.item.birhday}" required="true"
							effect="slideDown" pattern="dd/MM/yyyy" size="50"></p:calendar>

						<h:outputLabel for="birthPlace" value="Nơi Sinh " />
						<p:inputText id="birthPlace" value="#{mbTeacher.item.birthPlace}"
							required="false" label="Nơi Sinh" size="50" />

						<h:outputLabel for="originalPlace" value="Nguyên Quán " />
						<p:inputText id="originalPlace"
							value="#{mbTeacher.item.originalPlace}" required="false"
							label="Nguyên Quán" size="50" />

						<h:outputLabel for="address" value="Địa Chỉ " />
						<p:inputText id="address" value="#{mbTeacher.item.address}"
							required="false" label="Địa Chỉ" size="50" />

						<h:outputLabel for="email" value="Email " />
						<p:inputText id="email" value="#{mbTeacher.item.email}"
							required="false" label="Email" size="50" />

						<h:outputLabel for="degree" value="Học Vị " />
						<p:selectOneMenu style="width:350px"
							value="#{mbTeacher.item.degree}" required="false" id="degree">
							<f:selectItem itemLabel="Chọn..." itemValue="" />
							<f:selectItems value="#{mbTeacher.degree}" />
						</p:selectOneMenu>

						<h:outputLabel for="academicTitle" value="Học Hàm " />
						<p:selectOneMenu style="width:350px"
							value="#{mbTeacher.item.academicTitle}" required="false"
							id="academicTitle">
							<f:selectItem itemLabel="Chọn..." itemValue="" />
							<f:selectItems value="#{mbTeacher.academicTitles}" />
						</p:selectOneMenu>

						<h:outputLabel for="teacherType" value="Loại Giảng Viên " />
						<p:selectOneMenu style="width:350px"
							value="#{mbTeacher.item.teacherType}" required="false"
							id="teacherType">
							<f:selectItem itemLabel="Chọn..." itemValue="" />
							<f:selectItems value="#{mbTeacher.teacherType}" />
						</p:selectOneMenu>

						<h:outputText for="contractDate" value="Ngày Bắt Đầu Làm Việc "></h:outputText>
						<p:calendar id="contractDate" label="Ngày Sinh"
							value="#{mbTeacher.item.contractDate}" required="true"
							effect="slideDown" pattern="dd/MM/yyyy" size="50"></p:calendar>
						
						<h:outputLabel for="contractType" value="Loại Hợp Đồng " />
						<p:selectOneMenu style="width:350px"
							value="#{mbTeacher.item.contractType}" required="false"
							id="contractType">
							<f:selectItem itemLabel="Chọn..." itemValue="" />
							<f:selectItems value="#{mbTeacher.contractType}" />
						</p:selectOneMenu>	

						<h:outputLabel for="salaryFactor" value="Hệ Số Lương " />
						<p:inputText id="salaryFactor"
							value="#{mbTeacher.item.salaryFactor}" required="false"
							label="Hệ Số Lương" size="50" />

						<h:outputLabel for="teachingFactor" value="Hệ Số Tiết Dạy " />
						<p:inputText id="teachingFactor"
							value="#{mbTeacher.item.teachingFactor}" required="false"
							label="Hệ Số Tiết Dạy" size="50" />

						<h:outputLabel for="clazzId" value="Chủ Nhiệm Lớp " />
						<p:selectOneMenu style="width:350px"
							value="#{mbTeacher.item.clazzId}" required="false" id="clazzId">
							<f:selectItem itemLabel="Chọn..." itemValue="" />
							<f:selectItems value="#{mbTeacher.clazzMap}" />
						</p:selectOneMenu>

						<p:commandButton id="submitButton" value="Lưu"
							action="#{mbTeacher.doAdd}"
							update=":teacherForm:teacherTablePanel"
							oncomplete="handleTeacherRequest(xhr, status, args)" />
					</h:panelGrid>
				</h:form>
			</p:dialog>
		</ui:define>
	</ui:composition>
</h:body>
</html>